# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
from selenium.webdriver.common.action_chains import ActionChains
import unittest
import random
import time
from cookies import lasthopes, randomword
import re
import string
import sys
from selenium.webdriver.common.keys import Keys
from PIL import Image
from os import remove, listdir, sep
from os.path import basename, isfile
import tempfile
from warnings import warn
from baseclass import BaseClass

class reg_ok(BaseClass):
    def test_reg_ok(self):
        driver = self.driver
        #Link to auth
        inputElement = driver.find_element_by_css_selector("div.b-header-top-auth")\
                             .find_element_by_css_selector("span.g-pseudo-h")
        inputElement.click()
        #Auth popup
        auth_pop = self.wait_for_popub_name(u'Авторизация')
        #Link to registration
        regb = WebDriverWait(auth_pop, timeout=3)\
                .until(lambda dr: dr.find_element_by_css_selector(self.variables.reg_link))
        regb.click()
        #Reg popup
        reg_pop = WebDriverWait(driver, timeout=3)\
                    .until(lambda dr: dr.find_element_by_css_selector("div.mod_register"))\
                    .find_element_by_css_selector("div.b-popup-h")
        send_btn = reg_pop.find_elements_by_css_selector("input.b-sbutton-input")[0]
        #Credentials
        inp_mail = reg_pop.find_element_by_name('email')
        inp_mail.send_keys(randomword(4,7)+'@'+randomword(4,7)+'.'+randomword(2,3))
        inp_name = reg_pop.find_element_by_name('name')
        inp_name.send_keys(u'Василий Петрович Ничипоренко')
        txt_bfr = reg_pop.get_attribute("textContent")
        send_btn.click()
        WebDriverWait(driver, timeout=10).until(lambda dr: reg_pop.get_attribute("textContent")!=txt_bfr)
        assert u'Для завершения регистрации пройдите по ссылке, отправленной на указанную электронную почту'\
               in reg_pop.get_attribute("textContent")
